package com.qst.binzhou2022.utils;

import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import java.io.IOException;
import java.io.InputStream;

/**
 * @author spengda
 * @date 2022/4/715:25
 */
public class MybatisUtils {

    SqlSessionFactory sqlSessionFactory;

    private static MybatisUtils instance = new MybatisUtils();
    private MybatisUtils (){
        //获取
        String resource = "sqlMapConfig.xml";
        InputStream inputStream = null;
        try {
            inputStream = Resources.getResourceAsStream(resource);
        } catch (IOException e) {
            e.printStackTrace();
        }
        sqlSessionFactory = new SqlSessionFactoryBuilder().build(inputStream);
    }
    public static MybatisUtils getInstance() {
        return instance;
    }

    public SqlSession getSqlSession(){

        SqlSession sqlSession = sqlSessionFactory.openSession();

        return sqlSession;
    }
    public Object getMapper(Class classInfo){

        return  getSqlSession().getMapper(classInfo);


    }

}
